package com.margo.project.security.config;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

@Component
public class MargoUserDetailsService implements UserDetailsService{
	//
	Logger logger=LoggerFactory.getLogger(this.getClass());
	
	@SuppressWarnings("unused")
	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
		logger.info("loadUserByUsername");
	    List<GrantedAuthority> list = new ArrayList<GrantedAuthority>();
        GrantedAuthority au = new SimpleGrantedAuthority("ROLE_USER");
        list.add(au);
        //123456 自定义MD5加密后=e10adc3949ba59abbe56e057f20f883e
        JwtUser JwtUser = new JwtUser(username,"e10adc3949ba59abbe56e057f20f883e",list);
        if (JwtUser == null) {
            throw new UsernameNotFoundException(String.format("No user found with username."));
        }
        System.out.println(JwtUser);
        return JwtUser;
	}

}
